﻿using UnityEngine;

namespace Core
{
    public interface IAssetLoader
    {
        ETTask<T> LoadAssetAsync<T>(string path) where T : UnityEngine.Object;
    }

    [DisallowMultipleComponent]
    public class GameMono : RGMono, IAssetLoader
    {
        EventSpace eventSpace = new EventSpace();
        AssetSpace assetSpace = new AssetSpace();

        public void Subscribe<T>(EventHandler<T> handler) where T : struct, IEventData
        {
            eventSpace.Subscribe(handler);
        }

        public ETTask<T> LoadAssetAsync<T>(string path) where T : UnityEngine.Object
        {
            return assetSpace.LoadAssetAsync<T>(path);
        }

        public void AddAssetReference(string path)
        {
            assetSpace.AddAssetReference(path);
        }

        private void OnDestroy()
        {
            Dispose();
        }

        private void Dispose()
        {
            eventSpace.Dispose();
            assetSpace.Dispose();
        }
    }
}
